import { createRouter, createWebHashHistory } from 'vue-router';

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        // 重定向
        { path: '/', redirect: '/home' },
        {
            path: '/home',
            name: 'Home',
            redirect: "/article1",
            component: () => import('@/layout/index.vue'),
            meta: {
                title: '主页',
                keepAlive: true,
                requireAuth: false
            },
            children: [
                {
                    path: '/article1',
                    name: 'article1',
                    component: () => import('@/views/home.vue'),
                    meta: {
                        title: '文章1',
                        keepAlive: true,
                        requireAuth: false
                    },
                },
                {
                    path: '/article:id',
                    component: () => import('@/views/article.vue'),
                    meta: {
                        title: '文章',
                        keepAlive: true,
                        requireAuth: false
                    },
                },
            ],
        }]
});
let startTime = Date.now().toString()
let currentTime
router.beforeEach((to, from) => {
    if (to) {
        currentTime = Date.now()
        let stayTime = (currentTime - parseInt(startTime)) / 1000;
        console.log('待了' + stayTime + '秒');
        startTime = Date.now().toString()
    }

})
export default router;